﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAO;
using BUS;

namespace BUS
{
    public class SanPhamBus
    {
        public static bool ThemSanPham(SanPhamDto one)
        {
            bool result = false;
            if (SanPhamDao.kiemtraTonTai(one.ID) == false)
                result = SanPhamDao.ThemSanPham(one);

            return result;
        }

        public static bool xoaSanPham(int id)
        {
            bool result = false;
            if (SanPhamDao.kiemtraTonTai(id) == true)
                result = SanPhamDao.xoaSanPham(id);

            return result;   
        }

        public static bool CapnhatSanPham(SanPhamDto one)
        {
            bool result = false;
            if (SanPhamDao.kiemtraTonTai(one.ID) == true)
                result = SanPhamDao.CapnhatSanPham(one);

            return result;      
        }

        public static bool CapnhatDiemSanPham(int diem, int solandanhgia, int IDsanpham)
        {
            bool result = false;
            if (SanPhamDao.kiemtraTonTai(IDsanpham) == true)
                result = SanPhamDao.CapnhatDiemSanPham(diem, solandanhgia, IDsanpham);

            return result;      
        }

        public static int LaySoLuongSanPhamTheoKey(string key)
        {
            return SanPhamDao.LaySoLuongSanPhamTheoKey(key);
        }
        public static List<SanPhamDto> LayDanhSachSanPhamTheoKeyPaging(int start, int end, string key)
        {
            return SanPhamDao.LayDanhSachSanPhamTheoKeyPaging(start, end, key);
        }
        public static SanPhamDto LaySanPhamTheoID(int ID)
        {
            return SanPhamDao.LaySanPhamTheoID(ID);
        }

        public static SanPhamDto LaySanPhamTheoTen(String tensanpham)
        {
            return SanPhamDao.LaySanPhamTheoTen(tensanpham);
        }

        public static List<SanPhamDto> LayDanhSachSanPham()
        {
            return SanPhamDao.LayDanhSachSanPham();
        }
        public static List<SanPhamDto> LayDanhSachSanPhamPaging(int start,int end)
        {
            return SanPhamDao.LayDanhSachSanPhamPaging(start,end);
        }
        public static List<SanPhamDto> LayDanhSachSanPhamTheoLoai(int maloai)
        {
            return SanPhamDao.LayDanhSachSanPhamTheoLoai(maloai);
        }

        public static List<SanPhamDto> LayDanhSachSanPhamMoi()
        {
            return SanPhamDao.LayDanhSachSanPhamMoi();
        }

        public static List<SanPhamDto> LayDanhSachSanKhuyenMai()
        {
            return SanPhamDao.LayDanhSachSanKhuyenMai();
        }
        public static List<SanPhamDto> LayDanhSachSanKhuyenMaiLimit()
        {
            return SanPhamDao.LayDanhSachSanKhuyenMaiLimit();
        }
        public static List<SanPhamDto> LayDanhSachSanPhamGiamGia()
        {
            return SanPhamDao.LayDanhSachSanPhamGiamGia();
        }

        public static List<SanPhamDto> LayDanhSachSanPhamDuocYeuThich()
        {
            return SanPhamDao.LayDanhSachSanPhamDuocYeuThich();
        }

        public static List<SanPhamDto> LayDanhSachSanPhamBanChay()
        {
            return SanPhamDao.LayDanhSachSanPhamBanChay();
        }

        public static List<SanPhamDto> LayDanhSachSanPhamTimKiemNhanh(String keyword, int pageSize, int pageNum)
        {
            return SanPhamDao.LayDanhSachSanPhamTimKiemNhanh(keyword, pageSize, pageNum);
        }
        public static int LayTatCaSanPhamTimKiemNhanh(String keyword)
        {
            return SanPhamDao.LayTatCaSanPhamTimKiemNhanh(keyword);
        }
        public static int LayTatCaSanPhamTimKiemNC(String keyword, int loai, int giaTu, int giaDen, String khuyenmai)
        {
            return SanPhamDao.LayTatCaSanPhamTimKiemNC(keyword, loai, giaTu, giaDen, khuyenmai);
        }
        public static List<SanPhamDto> LayDanhSachSanPhamTimKiemNC(String keyword, int loai, int giaTu, int giaDen, String khuyenmai, int pageSize, int pageNum)
        {
            return SanPhamDao.LayDanhSachSanPhamTimKiemNC(keyword, loai, giaTu, giaDen, khuyenmai, pageSize, pageNum);
        }
        public static List<SanPhamDto> LayDanhSachSanPhamTheoLoaiPaging(int start, int end, int id)
        {
            return SanPhamDao.LayDanhSachSanPhamTheoLoaiPaging(start, end, id);
        }
        public static int LaySoLuongSanPhamTheoLoaiKey(string key, int id)
        {
            return SanPhamDao.LaySoLuongSanPhamTheoLoaiKey(key, id);
        }
        public static List<SanPhamDto> LayDanhSachSanPhamTheoLoaiKeyPaging(int start, int end, string key, int id)
        {
            return SanPhamDao.LayDanhSachSanPhamTheoLoaiKeyPaging(start, end, key, id);
        }
        //<NEW CODE>
        public static bool CapNhatSoLuongTon_DaBan(int id, int SoLuong)
        {
            return SanPhamDao.CapNhatSoLuongTon_DaBan(id, SoLuong);
        }
        //</NEW CODE>
    }
}
